package spark

import java.sql.{Connection, DriverManager}

object MySQLConnect {
  private var connection: Connection = _
  private val driver = "com.mysql.cj.jdbc.Driver"
  private val url = "jdbc:mysql://188.131.167.236/spark?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai"
  private val username = "java"
  private val password = "Java1234.."

  def conn(): Connection = {
    if(connection == null) {
      println(this.driver)
      Class.forName(this.driver)
      connection = DriverManager.getConnection(url, username, password)
    }
    connection
  }
}
